package com.transfer.service;

import com.transfer.dao.TransferDao;
import com.transfer.entity.AccountInfo;

public class TransferServiceImpl implements TransferService {
	private TransferDao dao;

	public void setDao(TransferDao dao) {
		this.dao = dao;
	}

	@Override
	public boolean trans(int id1, int id2, double money) throws Exception {
		AccountInfo account1 = dao.getAccount(id1);
		AccountInfo account2 = dao.getAccount(id2);
		account2.setBalance(account2.getBalance() + money);
		if (account1.getBalance() < money) {
			throw new Exception("金额不足");
		}
		account1.setBalance(account1.getBalance() - money);
		dao.update(account1);
		dao.update(account2);
		return true;
	}

}
